﻿/**
 * Create in 2012-4-3.
 */
package kit4j.tests.jdk.awt;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;

/**
 * 
 * @author MiniKnife
 *
 */
public class TestMouseEventByGetButton {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JFrame frame = getFrame();
		MouseListener listener = getMouseListener();
		frame.addMouseListener(listener);
		
		frame.setVisible(true);
	}
	
	static JFrame getFrame() {
		JFrame frame = new JFrame("Test Get Button");
		
		frame.setSize(400, 400);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		return frame;
	}
	
	static MouseListener getMouseListener() {
		return new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent evt) {
				int btn = evt.getButton();
				
				switch(btn) {
				case MouseEvent.BUTTON1:
					System.out.println("BUTTON1");
					break;
				case MouseEvent.BUTTON2:
					System.out.println("BUTTON2");
					break;
				case MouseEvent.BUTTON3:
					System.out.println("BUTTON3");
					break;
				default:
					System.out.println("UNKNOW");
				}
			}
		};
	}

}
